//package com.zkthink.ceres.app.sales.controller;
//
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.zkthink.base.R;
//import com.zkthink.base.request.PageParams;
//import com.zkthink.ceres.common.enums.YesOrNoEnum;
//import com.zkthink.ceres.order.dto.MemberOrderStatistics;
//import com.zkthink.ceres.order.service.OrderProductService;
//import com.zkthink.ceres.order.service.OrderService;
//import com.zkthink.ceres.promotion.dto.SalesApplyDTO;
//import com.zkthink.ceres.promotion.dto.SalesPageDTO;
//import com.zkthink.ceres.promotion.entity.Sales;
//import com.zkthink.ceres.promotion.entity.SalesCustomer;
//import com.zkthink.ceres.promotion.entity.SalesOrder;
//import com.zkthink.ceres.promotion.entity.SalesPromConfig;
//import com.zkthink.ceres.promotion.enums.SalesPromConfigTypeEnum;
//import com.zkthink.ceres.promotion.service.SalesPromConfigService;
//import com.zkthink.ceres.promotion.service.SalesService;
//import com.zkthink.ceres.promotion.entity.admin.SalesOrderPageVO;
//import com.zkthink.ceres.promotion.entity.web.SalesCustomerVO;
//import com.zkthink.ceres.promotion.entity.web.SalesMainInfoVO;
//import com.zkthink.ceres.promotion.entity.web.SalesStoreVO;
//import com.zkthink.ceres.promotion.entity.web.SubordinateSalesVO;
//import com.zkthink.context.BaseContextHandler;
//import com.zkthink.database.mybatis.conditions.Wraps;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import lombok.AllArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.validation.annotation.Validated;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
///**
// * Created by kellen on 2020/8/23.
// */
//
//@Slf4j
//@Validated
//@AllArgsConstructor
//@RestController
//@RequestMapping("/sales")
//@Api(value = "分销服务", tags = "分销服务")
//public class SalesController {
//
//  private SalesService salesService;
//
//  private SalesPromConfigService salesPromConfigService;
//
//  private OrderProductService orderProductService;
//
//  private OrderService orderService;
//
//  @ApiOperation("分销员申请")
//  @PostMapping("/apply")
//  public R apply(@RequestBody @Validated SalesApplyDTO applyDTO) {
//    Long mid = BaseContextHandler.getUserId();
//    applyDTO.setMid(mid);
//    //判断是否有申请过
//    Sales sales = salesService.queryByMidAndTenantCode(mid, applyDTO.getTenantCode());
//    if (null != sales) {
//      return R.fail("请勿重复申请");
//    }
//    MemberOrderStatistics memberOrderStatistics = orderService.getOrderStatisticsByMid(mid);
//    applyDTO.setPayOrderCount(memberOrderStatistics.getPayOrderCount());
//    applyDTO.setOrderSum(memberOrderStatistics.getOrderSum());
//    //保存申请记录
//    salesService.saveSales(applyDTO);
//    return R.success();
//  }
//
//  @ApiOperation(value = "查询是否已申请成为该店铺的分销员",notes = "参数只要传tenantCode即可")
//  @PostMapping("/hasApply")
//  public R hasApply(@RequestBody @Validated SalesApplyDTO applyDTO) {
//    Long mid = BaseContextHandler.getUserId();
//    applyDTO.setMid(mid);
//    //判断是否有申请过
//    Sales sales = salesService.queryByMidAndTenantCode(mid, applyDTO.getTenantCode());
//    if (null != sales) {
//      return R.success(1);
//    }
//    return R.success(0);
//  }
//
//  @ApiOperation(value = "查询该分销员分销的店铺",notes = "model参数只要传tenantCode即可")
//  @PostMapping("/findSaleStoreList")
//  public R<IPage<SalesStoreVO>> findSaleStoreList(@RequestBody PageParams<Sales> salesPageDTO) {
//    Long mid = BaseContextHandler.getUserId();
//    IPage<SalesStoreVO> salesPage = salesService.findSaleStoreList(mid,salesPageDTO);
//    if (null != salesPage) {
//      return R.success(salesPage);
//    }
//    return R.fail("查询失败");
//  }
//
//  @ApiOperation(value = "查询分销员的主要信息",notes = "参数只要传tenantCode即可")
//  @PostMapping("/querySalesMainInfo")
//  public R<SalesMainInfoVO> querySalesMainInfo(@RequestBody Sales sales) {
//    Long mid = BaseContextHandler.getUserId();
//    SalesMainInfoVO salesMainInfoVO = salesService.querySalesMainInfo(mid, sales.getTenantCode());
//    if (null != salesMainInfoVO) {
//      return R.success(salesMainInfoVO);
//    }
//    return R.fail("查询失败");
//  }
//
//  @ApiOperation(value = "查询累计奖励",notes = "model参数只要传tenantCode即可")
//  @PostMapping("/findSalesOrderPage")
//  public R<IPage<SalesOrderPageVO>> findSalesOrderPage(@RequestBody PageParams<SalesOrder> pageParams) {
//    Long mid = BaseContextHandler.getUserId();
//    pageParams.getModel().setMid(mid);
//    IPage<SalesOrderPageVO> salesOrderPage = salesService.findSalesOrderPage(pageParams);
//    if (null != salesOrderPage) {
//      for(SalesOrderPageVO salesOrderPageVO:salesOrderPage.getRecords()){
//        salesOrderPageVO.setProductCount(orderProductService.queryProductCount(salesOrderPageVO.getOrderNo()));
//        salesOrderPageVO.getDisplayControlMap().put("productCount",salesOrderPageVO.getProductCount());
//      }
//      return R.success(salesOrderPage);
//    }
//    return R.fail("查询失败");
//  }
//
//  @ApiOperation(value = "查询累计客户",notes = "参数只要传tenantCode即可")
//  @PostMapping("/findSalesCustomerList")
//  public R<IPage<SalesCustomerVO>> findSalesCustomerList(@RequestBody PageParams<SalesCustomer> pageParams) {
//    Long mid = BaseContextHandler.getUserId();
//    pageParams.getModel().setMid(mid);
//    IPage<SalesCustomerVO> salesPage = salesService.findSalesCustomerList(pageParams);
//    if (null != salesPage) {
//      return R.success(salesPage);
//    }
//    return R.fail("查询失败");
//  }
//
//  @ApiOperation(value = "查询累计分销员",notes = "参数只要传tenantCode即可")
//  @PostMapping("/findSubordinateSalesList")
//  public R<IPage<SubordinateSalesVO>> findSubordinateSalesList(@RequestBody PageParams<Sales> pageParams) {
//    Long mid = BaseContextHandler.getUserId();
//    pageParams.getModel().setMid(mid);
//    IPage<SubordinateSalesVO> salesPage = salesService.findSubordinateSalesList(pageParams);
//    if (null != salesPage) {
//      return R.success(salesPage);
//    }
//    return R.fail("查询失败");
//  }
//
//  @ApiOperation(value = "查询我的分销记录",notes = "参数只要传tenantCode即可")
//  @PostMapping("/findMySalesPage")
//  public R<IPage<SalesOrderPageVO>> findMySalesPage(@RequestBody PageParams<SalesOrder> pageParams) {
//    Long mid = BaseContextHandler.getUserId();
//    pageParams.getModel().setMid(mid);
//    IPage<SalesOrderPageVO> salesPage = salesService.findMySalesPage(pageParams);
//    if (null != salesPage) {
//      for(SalesOrderPageVO salesOrderPageVO:salesPage.getRecords()){
//        salesOrderPageVO.setProductCount(orderProductService.queryProductCount(salesOrderPageVO.getOrderNo()));
//        salesOrderPageVO.getDisplayControlMap().put("productCount",salesOrderPageVO.getProductCount());
//      }
//      return R.success(salesPage);
//    }
//    return R.fail("查询失败");
//  }
//
//  @ApiOperation(value = "查询推广配置",notes = "参数只要传tenantCode 和 type即可即可")
//  @PostMapping("/findSalesPromConfig")
//  public R<SalesPromConfig> findSalesPromConfig(@RequestBody SalesPromConfig salesPromConfig) {
//    SalesPromConfig config = salesPromConfigService.getOne(Wraps.<SalesPromConfig>lbQ()
//            .eq(SalesPromConfig::getTenantCode,salesPromConfig.getTenantCode())
//            .eq(SalesPromConfig::getType, salesPromConfig.getType())
//            .eq(SalesPromConfig::getIsDelete, YesOrNoEnum.NO.getCode()));
//    if (null != config) {
//      return R.success(config);
//    }
//    return R.fail("查询失败");
//  }
//
//}
